<%--
  Created by IntelliJ IDEA.
  User: Jamin
  Date: 2019/1/24
  Time: 15:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css">
    <script src="../../My97DatePicker/WdatePicker.js"></script>
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <style>
        .account{
            width: 191px;
        }
        .tops{
            width: auto;
            height: 59px;
            background: #009688;
        }
        body{
            background: white;
        }
    </style>
</head>
<body>
<div class="tops"></div>

<!--优惠券信息新增表单-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>优惠券信息新增</legend>
</fieldset>
<form id="a" class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">优惠券描述</label>
        <div class="layui-input-inline">
            <input type="text" name="c_description"  lay-verify="c_description" autocomplete="off" class="layui-input" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">满足条件</label>
        <div class="layui-input-inline">
            <input type="text" name="c_term" required lay-verify="c_term" autocomplete="off" class="layui-input" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠价格</label>
        <div class="layui-input-inline">
            <input type="text" name="c_vipprice"  lay-verify="c_vipprice" autocomplete="off" class="layui-input" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">截止时间</label>
        <div class="layui-input-inline">
            <input type="text" name="c_deadline" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" lay-verify="c_deadline" autocomplete="off" class="layui-input" value="">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="formDemo" >立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        form.verify({
            c_description: function(value){
                if(value.length==0){
                    return '优惠券描述不得为空';
                }
            },
            c_term:
                [/^[1-9]\d*|0$/
                    ,'使用条件输入不正确'
                ]

            ,c_vipprice:[/^[1-9]\d*|0$/
                ,'优惠金额输入不正确']

        });
        /**
         * 会员信息的修改
         * 监听提交
         */
        form.on('submit(formDemo)', function(data){

            var index = parent.layer.getFrameIndex(window.name);
alert("a");
            $.ajax({
                url:"/InsertCoupon",   //请求路径
                datatype:"json",//返回的格式
                data:$("#a").serialize(), //参数
                type:"POST", //什么请求
                success:function (data) { //请求成功以后
                    //AJAX成功以后返回的
                    var obj = eval('(' + data + ')');
                    if (obj.insert){
                        alert("新增成功");
                        layui.close(1);
                    } else{
                        alert("新增失败");
                        window.location.href="InsertCoupon.jsp";
                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>

